{% extends "home/common/layout.html" %}

{% block content %}
<section class="content">
    <div class="page-header">
        <h3>
            Job列表
            {% if set_flag %}
            <a class="btn btn-primary pull-right"
               href="{{ GlobalUrlService.buildHomeUrl('/job/index/set') }}">
                <i class="fa fa-plus" aria-hidden="true"></i> Job
            </a>
            {% endif %}
        </h3>
    </div>
    <div class="row">
        <div class="col-md-12 col-lg-12">
            <div class="box">
                <div class="box-header with-border">
                    <div class="row">
                        <div class="col-xs-12 col-md-12 col-lg-12">
                            <form class="form-inline wrap_search">
                                <div class="form-group">
                                    <select class="form-control" name="cate_id">
                                        <option value="0">分类</option>
                                        {% for _key,_item in cate_map.items() %}
                                        <option {% if _item.id == sc.cate_id  %} selected {% endif %} value="{{_item.id}}">{{_item.name}}</option>
                                       {% endfor %}
                                    </select>
                                </div>
                                <div class="form-group">
                                    <select class="form-control" name="owner_uid">
                                        <option value="0">负责人</option>
                                        {% for _key,_item in staff_map.items() %}
                                        <option {% if _item.id == sc.owner_uid  %} selected {% endif %} value="{{_item.id}}">{{_item.name}}</option>
                                       {% endfor %}
                                    </select>
                                </div>
                                <div class="form-group">
                                    <select class="form-control" name="env_id">
                                        <option value="0">运行环境</option>
                                        {% for _key,_desc in server_env_map.items() %}
                                        <option {% if _key == sc.env_id  %} selected {% endif %} value="{{_key}}">{{_desc}}</option>
                                        {% endfor %}
                                    </select>
                                </div>
                                <div class="form-group" style="width:12%">
                                    <select class="form-control" name="server_id"  style="width:100%">
                                        <option value="0">服务器</option>
                                        {% for _key,_item in server_map.items() %}
                                        <option {% if _item.id == sc.server_id  %} selected {% endif %} value="{{_item.id}}">{{_item.name}}[ {{_item.note}} ]</option>
                                        {% endfor %}
                                    </select>
                                </div>
                                <div class="form-group">
                                    <select class="form-control" name="status">
                                        <option value="{{ CommonConstant.default_status_neg_99 }}">调度状态</option>
                                        {% for _key,_desc in job_status_map.items() %}
                                        <option {% if _key == sc.status  %} selected {% endif %} value="{{_key}}">{{_desc}}</option>
                                        {% endfor %}
                                    </select>
                                </div>

                                <div class="form-group">
                                    <select class="form-control" name="display_status">
                                        <option value="{{ CommonConstant.default_status_neg_99 }}">展示状态</option>
                                        {% for _key,_desc in display_status_map.items() %}
                                        <option {% if _key == sc.display_status  %} selected {% endif %} value="{{_key}}">{{_desc}}</option>
                                        {% endfor %}
                                    </select>
                                </div>
                                <div class="form-group">
                                    <select class="form-control" name="job_type">
                                        <option value="{{ CommonConstant.default_status_neg_99 }}">类型</option>
                                        {% for _key,_desc in job_type_map.items() %}
                                        <option {% if _key == sc.job_type  %} selected {% endif %} value="{{_key}}">{{_desc}}</option>
                                        {% endfor %}
                                    </select>
                                </div>
                                <div class="form-group">
                                    <select class="form-control" name="job_level">
                                        <option value="{{ CommonConstant.default_status_neg_99 }}">级别</option>
                                        {% for _key,_desc in job_level_map.items() %}
                                        <option {% if _key == sc.job_level  %} selected {% endif %} value="{{_key}}">{{_desc}}</option>
                                        {% endfor %}
                                    </select>
                                </div>
                                <div class="form-group" style="width:19%">
                                    <input type="text" style="width:100%" class="form-control col-sm-12 col-md-3 mb-2 mr-2" name="kw"
                                           placeholder="请输入搜索关键词、命令、Job_id" value="{{sc['kw']}}">
                                </div>
                                <div class="form-group">
                                    <button type="submit" class="btn btn-primary">搜索</button>
                                </div>
                                <a class="btn btn-link" href="{{ GlobalUrlService.buildHomeUrl('/job/index/index') }}">重置搜索</a>
                            </form>
                        </div>
                    </div>
                </div>
                <div class="box-body table-responsive no-padding job_list_wrap">
                    <table class="table table-bordered">
                        <thead>
                        <tr>
                            <th width="6%">ID</th>
                            <th>名称</th>
                            <th width="14%">服务器/运行环境</th>
                            <th width="14%">负责人/相关人</th>
                            <th width="13%">下次运行时间</th>
                            <th width="6%">运行周期</th>
                            <th width="10%">运行状态</th>
                            <th width="6%">系统调度</th>
                            <th width="14%">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {% if list %}
                        {% for item in list %}
                        <tr {% if item.is_del %} class="bg-warning" {% endif %}>
                            <td>{{ item.id }}</td>
                            <td>
                                <a href="{{ GlobalUrlService.buildHomeUrl('/job/index/info') }}?id={{ item.id }}">
                                    {% if item.cate_name %}【{{ item.cate_name}}】{% endif %}{{ item.name }}
                                </a>
                            </td>
                            <td>{{ item.server_name }} / {{ item.env_name }}</td>
                            <td>{{ item.owner_name }} / {{ item.relate_name }}</td>
                            <td>{{ item.next_run_time }}</td>
                            <td>
                                {% if item.job_type == CommonConstant.default_status_true %}
                                    {{ item.run_interval_desc }}
                                {% else %}
                                    {{ CommonConstant.job_type_map[ item.job_type ] }}
                                {% endif %}
                            </td>
                            <td>{{ item.run_status_desc }}</td>
                            <td>{{ item.job_status_desc }}</td>
                            <td>
                                {% if set_flag %}
                                <a class="btn btn-link"
                                   href="{{ GlobalUrlService.buildHomeUrl('/job/index/set') }}?id={{ item.id }}">修改</a>
                                {% endif %}

                                <div class="btn-group">
                                    <button type="button" class="btn btn-primary">操作</button>
                                    <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown"
                                            aria-haspopup="true" aria-expanded="false">
                                        <span class="caret"></span>
                                    </button>
                                    <ul class="dropdown-menu">
                                        {% if item.status %}
                                        <li>
                                            <a class="ops" href="{{ GlobalUrlService.buildNull() }}"
                                               data-act="system_not_run" data-id="{{ item.id }}"
                                               data-title="系统不在调度：指的是以后不在被执行调度了">系统不在调度</a>
                                        </li>
                                        {% else %}
                                        <li>
                                            <a class="ops" href="{{ GlobalUrlService.buildNull() }}"
                                               data-act="system_run" data-id="{{ item.id }}"
                                               data-title="系统调度：指的是在下一次周期会被继续执行调度">系统调度</a>
                                        </li>
                                        {% endif %}
                                        <li>
                                            <a class="ops" href="{{ GlobalUrlService.buildNull() }}" data-act="run_next"
                                               data-id="{{ item.id }}" data-title="将调度时间改为下一分钟调度">立即调度</a>
                                        </li>
                                        <li role="separator" class="divider"></li>
                                        <li>
                                            <a href="{{ GlobalUrlService.buildHomeUrl('/job/index/set') }}?id={{ item.id }}&act=copy">复制Job</a>
                                        </li>
                                        <li role="separator" class="divider"></li>
                                        <li>
                                            <a href="{{ GlobalUrlService.buildHomeUrl('/job/tools/log') }}?job_id={{ item.id }}">查看日志</a>
                                        </li>
                                        <li role="separator" class="divider"></li>
                                        <li>
                                            <a class="ops" href="{{ GlobalUrlService.buildNull() }}" data-act="kill" data-id="{{ item.id }}" data-title="强制终止Job将杀死Job即 kill -9 <br/>杀死一个job需要1-2分钟">强制终止Job</a>
                                        </li>
                                        <li role="separator" class="divider"></li>
                                        {% if item.is_del %}
                                        <li>
                                            <a class="ops" href="{{ GlobalUrlService.buildNull() }}" data-act="recovery"
                                               data-id="{{ item.id }}">恢复</a>
                                        </li>
                                        {% else %}
                                        <li>
                                            <a class="ops" href="{{ GlobalUrlService.buildNull() }}" data-act="del"
                                               data-id="{{ item.id }}">隐藏</a>
                                        </li>
                                        {% endif %}
                                    </ul>
                                </div>

                            </td>
                        </tr>
                        {% endfor %}
                        {% else %}
                        <tr>
                            <td colspan="9" class="text-center">(＞﹏＜)没有数据</td>
                        </tr>
                        {% endif %}
                        </tbody>
                    </table>
                </div>
                <div class="box-footer clearfix">
                    {% include 'common/pagenation.html' %}
                </div>
            </div>
        </div>
    </div>
</section>
{% endblock %}
{% block css %}
<style type="text/css">
    #修复按钮组被表格遮住问题

    @media (max-width: 767px) {
        .table-responsive .dropdown-menu,
        .table-responsive .dropdown-toggle {
            position: static !important;
        }
    }

    @media (min-width: 768px) {
        .table-responsive {
            overflow: visible;
        }
    }
</style>
{% endblock %}
{%block js %}
<script src="{{ GlobalUrlService.buildWWWStaticUrl('/js/home/job/index/index.js') }}"></script>
{% endblock %}